package com.mall.controller;

import com.mall.pageResult.PageResult;
import com.mall.pojo.SmsHomeAdvertise;
import com.mall.pojo.SmsHomeRecommendSubject;
import com.mall.service.HomeAdvertiseService;
import com.mall.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/advertise")
public class HomeAdvertiseController {

    @Autowired
    private HomeAdvertiseService homeAdvertiseService;

    /**
     * 分页查询首页推广告
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @param endTime
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult<SmsHomeAdvertise>> list(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                     @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                     @RequestParam(required = false) String name,
                                                     @RequestParam(required = false) String endTime,
                                                     @RequestParam(required = false) Integer type) {
        PageResult<SmsHomeAdvertise> result = homeAdvertiseService.list(pageNum, pageSize, name, endTime, type);
        return Result.success(result, "操作成功");
    }

    /**
     * 修改首页广告上下线状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result<Integer> updateStatus(@PathVariable Integer id, Integer status) {
        Integer count = homeAdvertiseService.updateStatus(id, status);
        return Result.success(count, "操作成功");
    }

    /**
     * 添加广告
     *
     * @param advertise
     * @return
     */
    @PostMapping("/create")
    public Result<Integer> create(@RequestBody SmsHomeAdvertise advertise) {
        Integer count = homeAdvertiseService.create(advertise);
        return Result.success(count, "操作成功");
    }

    /**
     * 获取广告详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SmsHomeAdvertise> advertiseMsg(@PathVariable Integer id) {
        SmsHomeAdvertise advertise = homeAdvertiseService.advertiseMsg(id);
        return Result.success(advertise, "操作成功");
    }

    /**
     * 修改广告
     * @param advertise
     * @return
     */
    @PostMapping("/update/{id}")
    public Result<Integer> update(@RequestBody SmsHomeAdvertise advertise) {
        Integer count = homeAdvertiseService.update(advertise);
        return Result.success(count,"操作成功");
    }

    /**
     * 批量删除广告
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result<Integer> delete(Long[] ids){
        Integer count = homeAdvertiseService.delete(ids);
        return Result.success(count, "操作成功");
    }

}
